package net1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {
    private static final int port = 8888;

    public static void main(String[] args) throws IOException {
        ServerSocket server = new ServerSocket(port);
        while (true) {
            System.out.println("------------------------------------");
            System.out.println("等待客户端建立TCP连接...");
            Socket client = server.accept();
            System.out.println("客户端ip :" + client.getInetAddress().getHostAddress());
            System.out.println("客户端port :" + client.getPort());
            System.out.println("接收到客户端请求：>>");
            InputStream inputStream = client.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
            String line;

            while ((line = bufferedReader.readLine()) != null) {
                System.out.println(line);
            }
            client.close();
        }
    }
}
